package lab_2;

import java.io.File;

/**
 * MyLogger for output to file or console
 * @author pacific
 */
public class MyLogger {
    public static final int LOG_TO_FILE = 1 ;
    public static final int LOG_TO_CONSOLE = 2 ;

    private static File fileForLog = new File("Logs.txt") ;

    
    private static int typeOfLog = LOG_TO_CONSOLE ;
    
    /** Write message to selected output */
    public static void putMessange(String msg) {
        switch (getTypeOfLog()) {
            case LOG_TO_FILE :
                break ;
            case LOG_TO_CONSOLE :
                System.out.println(msg) ;
                System.out.flush() ;
                break ;
        }
    }


    /**
     * Write message to selected output
     * @param msg - message for output
     * @param ex - Exception
     */
    public void putMessange(String msg, Exception ex) {
        switch (getTypeOfLog()) {
            case LOG_TO_FILE:
                break;
            case LOG_TO_CONSOLE:
                System.out.println(msg);
                System.out.println( ex.getStackTrace() ) ;
                System.out.flush();
                break;
        }
    }


    //-----Fields-----

    private static int getTypeOfLog() {
        return typeOfLog;
    }
    private File getFileForLog() {
        return fileForLog ;
    }
}
